package com.ds.infra.rpc.registry.util;

import io.netty.util.internal.StringUtil;
import lombok.experimental.UtilityClass;

/**
 * 作用：服务键工具类
 *
 * @author WeiShaoying
 */
@UtilityClass
public class ServiceKeyUtils {
    public static String buildServiceKey(String serviceName, String version) {
        if (StringUtil.isNullOrEmpty(serviceName) || StringUtil.isNullOrEmpty(version)) {
            throw new IllegalArgumentException("serviceName or version is null");
        }
        return String.join(":", serviceName, version);
    }

    public static String parseServiceName(String serviceKey) {
        return serviceKey.split(":")[0];
    }

    public static String parseVersion(String serviceKey) {
        return serviceKey.split(":")[1];
    }
}
